package com.xjy.rpcconsume.service;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

@RestController
@RequestMapping("/test")
public class testController {

    @PostMapping("/upload")
    public String upLoad(MultipartFile file) throws IOException {

        URL resource = this.getClass().getResource("/");
        System.out.println(resource);
        String property = System.getProperty("user.dir");
        String url = property + File.separator + "upload" + File.separator;
        System.out.println(property);
        System.out.println(url);
        File file1 = new File(url);
        boolean mkdir = file1.mkdir();
        boolean directory = file1.isDirectory();
        boolean file2 = file1.isFile();
        File copy = new File(url,"copy.txt");
        file.transferTo(copy);

        System.out.println(file.getOriginalFilename());
        return url + "copy.txt";

    }

    @PostMapping("/download")
    public String download(String uri) throws IOException {

        return null;

    }
}
